package biz.alla.market.dao.impl;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import biz.alla.market.dao.UserDao;
import biz.alla.market.domain.User;

public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

    @Override
    public User isValidUser(String username, String password) {
	Criteria criteria = createCriteria();
	criteria.add(Restrictions.eq("username", username));
	criteria.add(Restrictions.eq("password", password));

	Object uniqueResult = criteria.uniqueResult();
	return uniqueResult != null ? (User) uniqueResult : null;
    }

    private Criteria createCriteria() {
	return getSession().createCriteria(User.class);
    }
}
